var model_fail = "指纹设配获取失败，请联系管理员！";
/***
 * 验证设备是否接入正确
 */
function getOCXObject(){
	if(isFingerPrint()){
		var status = finger.FPIGetFeature(0,5000);
		if(status != 0){
			alertError(model_fail);
	    	return false;
	    }
		return true;
	}
}

/***
 * 检测是否 OCX是否加载成功
 */
function isFingerPrint(){
	if(finger == null || finger == undefined || finger == ''){
		alertError('OCX插件未加载成功,请检查IE安全设置！');
		return false;
	}
	return true;
}


/**
 * 采集指纹模板
 */
function collectFingerTemplate() {
	if  (finger == null || finger == undefined || finger == '') {
		alertError('OCX插件未加载成功,请检查IE安全设置！');
		return "";
	}
	try {
		var ret = finger.FPIFL_OpenDevice(0,0,0);
		if(ret == 0) {
			ret=finger.FPIFL_GetImage();
			ret = finger.FPIFL_UpImage();
			ret = finger.FPIFL_ChipGenChar();
			var data1 = finger.FPIFL_UpChar();
			
			ret = finger.FPIFL_GetImage();
			ret = finger.FPIFL_UpImage();
			ret = finger.FPIFL_ChipGenChar();
			var data2 = finger.FPIFL_UpChar();
			
			ret = finger.FPIFpMatch(data1, data2, 3);
			if (ret != 0) {
				alertError("指纹差异过大，采集失败！");
				return "";
			}

			ret = finger.FPIFL_GetImage();
			ret = finger.FPIFL_UpImage();
			ret = finger.FPIFL_ChipGenChar();
			var data3 = finger.FPIFL_UpChar();
			
			ret = finger.FPIFpMatch(data2, data3, 3);
			if (ret != 0) {
				alertError("指纹差异过大，采集失败！");
				return "";
			}
			
			ret=finger.FPIFL_CloseDevice();
			return data2;
		} else {
			alertError("设备初始化异常，请检查设备情况！");
			return "";
		}
	} catch (e) {
		alertError("采集失败，请检查设备情况！");
		return "";
	}
}


/**
 * 采集指纹特征
 */
function collectFingerFeatrue() {
	if (finger == null || finger == undefined || finger == ''){
		alertError('OCX插件未加载成功,请检查IE安全设置！');
		return "";
	}
	try {
		var ret = finger.FPIFL_OpenDevice(0,0,0);
		if(ret == 0){
			ret=finger.FPIFL_GetImage();
			ret = finger.FPIFL_UpImage();
			ret = finger.FPIFL_ChipGenChar();
			var data = finger.FPIFL_UpChar();
			ret=finger.FPIFL_CloseDevice();
			return data;
		} else {
			alertError("设备初始化异常，请检查设备情况！");
			return "";
		}
	} catch (e) {
		alertError("采集失败，请检查设备情况！");
		return "";
	}
}

